﻿Imports Oracle.DataAccess.Client
Public Class fListaTipoProducto
    Private lTipoProd As String
    Public ReadOnly Property idTipoProd() As String
        Get
            Return lTipoProd
        End Get
    End Property

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub consultar()
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        cmd.CommandText = "SELECT IDTIPOPRODUCTO, DESCRIPCION FROM PRO_TIPOPRODUCTO "
        Dim qWhere As String = ""
        If Me.txtDescripTipo.Text.Trim.Length > 0 Then
            qWhere = "WHERE DESCRIPCION LIKE '%" & txtDescripTipo.Text & "%'"
        End If
        Try
            Conn.Open()
            cmd.CommandText &= qWhere
            DsProductos.PRO_TIPOPRODUCTO.Clear()
            DsProductos.PRO_TIPOPRODUCTO.Load(cmd.ExecuteReader)
            Conn.Close()
            PRO_TIPOPRODUCTODataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub
    Private Sub btnConsulta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsulta.Click
        Try
            consultar()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub PRO_TIPOPRODUCTODataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles PRO_TIPOPRODUCTODataGridView.CellMouseDoubleClick
        If e.RowIndex >= 0 Then
            lTipoProd = PRO_TIPOPRODUCTODataGridView.Rows(e.RowIndex).Cells("IDTIPOPRODUCTO").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub AsignaTipoProducto(ByVal Fila As Integer)
        If Fila >= 0 Then
            lTipoProd = PRO_TIPOPRODUCTODataGridView.Rows(Fila).Cells("IDTIPOPRODUCTO").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub PRO_TIPOPRODUCTODataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles PRO_TIPOPRODUCTODataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaTipoProducto(PRO_TIPOPRODUCTODataGridView.CurrentRow.Index)
        End If
    End Sub

    Private Sub txtDescripTipo_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDescripTipo.KeyDown
        Try

            Select Case e.KeyCode
                Case 13
                    consultar()
            End Select
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
End Class